//首页导航
function nav(){
	$("#mod_headerNavigat li").hover(function(){
		$(this).addClass("first_");
	},function(){
		$(this).removeClass("first_");
	});
}; 
//产品tab
function setTab(name,cursel,n){
	for(var i=1;i<=n;i++){
		var menu=document.getElementById(name+i);
		var con=document.getElementById("con_"+name+"_"+i);
		menu.className=i==cursel?"hover":"";
		document.getElementById("titleTabnav").innerHTML=i==cursel?menu.innerHTML+"产品":"供应产品";
		con.style.display=i==cursel?"block":"none";
	}
}

//只能输入数字
function JHshNumberText() {
	if (!(((window.event.keyCode >= 48) && (window.event.keyCode <= 57) || window.event.keyCode == 46))) {
		window.event.keyCode = 0
	}
}

//去除空格
function cTrim(sInputString,iType){
	var sTmpStr = ' ';
	var i = -1;
		if(iType == 0 || iType == 1){
  		while(sTmpStr == ' '){
   			++i;
   			sTmpStr = sInputString.substr(i,1);
  		}
  		sInputString = sInputString.substring(i);
 	}
	if(iType == 0 || iType == 2) {
  		sTmpStr = ' ';
  		i = sInputString.length;
  			while(sTmpStr == ' '){
   				--i;
   				sTmpStr = sInputString.substr(i,1);
  			}
  		sInputString = sInputString.substring(0,i+1);
 	}
 	return sInputString;
}

//AJAX方式传入图片KEY得到图片路径
function asyncReloadImg(){
	//async:false
	$(".shopimagekey").each(function(){
		var img = $(this);
		var imgkey = img.attr("title");
		$.get("/shop/ajax/getimage.html",{imgkey:imgkey},function(data) {
			//if(data != "noimg")
			img.attr("src",data);
		});
	});
}
//ajax方式得到用户登录信息
function getLoginInfo(){
	$.get("/shop/ajax/getlogininfo.html",{},function(data) {
		if(data == "nologin"){
			alert(data);
			return "nologin";
		}else{
			alert(data.username);
			return data.username;
		}
	});
}
//AJAX方式LOGIN
function loginAjax(form){
	if(cTrim(form.username.value,0)==""){
		alert("用户名不能为空");
		form.username.focus();
		return false;
	}
	if(cTrim(form.password.value,0)==""){
		alert("密码不能为空");
		form.password.focus();
		return false;
	}
	$.post("/shop/ajax/login.html",{username:form.username.value,password:form.password.value,service:form.service.value,serviceToken:form.serviceToken.value},function(data) {
		if(data == "LOGIN_SUCCESS"){
			//alert("登录成功");
			window.location.reload();
		}else if(data == "LOGIN_ERROR"){
			//alert("登录失败");
		}
	});
}
//正常方式LOGIN
function login(form){
	if(cTrim(form.username.value,0)==""){
		alert("用户名不能为空");
		form.username.focus();
		return false;
	}
	if(cTrim(form.password.value,0)==""){
		alert("密码不能为空");
		form.password.focus();
		return false;
	}
	form.submit();
}



/**
 * 联系人名片弹框
 * */
function contactCard(){
	var btn = $("#showContactCard"),
		offset = btn.offset(),
		obj = $("#shop_list_17"),
		btnHeight = btn.height(),
		btnTop = offset.top,
		btnLeft = offset.left;

	var ary = $("#showContactCard,#shop_list_17")
	$("body").eq(0).append(obj);//把弹框元素插入到文档BODY DOM最低端;
	ary.live("mouseover",function(){
		btn.addClass('hot');
		obj.css({
			left:btnLeft,
			top:btnTop + btnHeight - 2,
			position:"absolute"
		});
		obj.show();
		return false;
	});
	ary.live("mouseout",function(){
		btn.removeClass("hot");
		obj.hide();
	});
}






//shop 全站商铺公共脚本
$(function(){
	//nav(); //导航相关
	
	//联系人名片弹框
	contactCard();
	
});





